from sklearn.svm import LinearSVC, SVC
import matplotlib.pyplot as plt
from sklearn.model_selection import cross_val_score

# from sklearn.datasets import make_blobs
# x,y = make_blobs(n_samples=50, centers=2, random_state=0, cluster_std=0.6)
# plt.scatter(x[:,0],x[:,1],c=y,s=50, cmap="rainbow")
# plt.show()
#
# print(cross_val_score(LinearSVC(), x, y, cv=5, scoring='accuracy').mean())
# print(cross_val_score(SVC(kernel='linear'), x, y, cv=5, scoring='accuracy').mean())

# from sklearn.datasets import make_circles
# x, y = make_circles(n_samples=1000, noise=0.03, factor=0.6)
# plt.scatter(x[:,0],x[:,1],c=y,s=10, cmap="rainbow")
# # plt.show()


# print(cross_val_score(SVC(kernel='linear'), x, y, cv=5, scoring='accuracy').mean())
print(cross_val_score(SVC(kernel='rbf'), x, y, cv=5, scoring='accuracy').mean())

"""
画图
"""
from sklearn.datasets import make_circles
import numpy as np
X, y = make_circles(n_samples=1000, noise=0.03, factor=0.6)
r = np.exp(-(X**2).sum(1))
rlim = np.linspace(min(r),max(r),0.2)
from mpl_toolkits import mplot3d
def plot_3D(elev=30,azim=30,X=X,y=y):
    ax = plt.subplot(projection="3d")
    ax.scatter3D(X[:, 0], X[:, 1], r, c=y, s=50, cmap='rainbow')
    ax.view_init(elev=elev, azim=azim)
    ax.set_xlabel("x")
    ax.set_ylabel("y")
    ax.set_zlabel("r")
    plt.show()
plot_3D()

